<?php

namespace app\common\model;

use think\facade\Validate;
use think\Model;

class Ads extends Model
{
    public function saveData($data)
    {
        $validate = Validate::make([
            'title' => 'require',
        ], [
            'title' => '标题必选',
        ]);
        if (!$validate->check($data)) {
            exception($validate->getError());
        }
        if (isset($data['id'])) {
            //更新
            $res = $this->where('id', $data['id'])->update($data);
        } else {
            //添加
            $res = $this->insertGetId($data);
        }
        return $res;
    }
}
